package com.stylefeng.guns.modular.hhtb.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.modular.hhtb.model.LogStatedccDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.hhtb.model.LogStatedcc;
import com.stylefeng.guns.modular.hhtb.service.ILogStatedccService;

import java.util.List;
import java.util.Map;

/**
 * 猫币定期流水控制器
 *
 * @author fengshuonan
 * @Date 2018-08-27 14:00:35
 */
@Controller
@RequestMapping("/logStatedcc")
public class LogStatedccController extends BaseController {

    private String PREFIX = "/hhtb/logStatedcc/";

    @Autowired
    private ILogStatedccService logStatedccService;

    /**
     * 跳转到猫币定期流水首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "logStatedcc.html";
    }

    /**
     * 跳转到添加猫币定期流水
     */
    @RequestMapping("/logStatedcc_add")
    public String logStatedccAdd() {
        return PREFIX + "logStatedcc_add.html";
    }

    /**
     * 跳转到修改猫币定期流水
     */
    @RequestMapping("/logStatedcc_update/{logStatedccId}")
    public String logStatedccUpdate(@PathVariable Integer logStatedccId, Model model) {
        LogStatedcc logStatedcc = logStatedccService.selectById(logStatedccId);
        model.addAttribute("item",logStatedcc);
        LogObjectHolder.me().set(logStatedcc);
        return PREFIX + "logStatedcc_edit.html";
    }

    /**
     * 获取猫币定期流水列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(LogStatedccDto logStatedcc) {
        Page<Map<String,Object>> page = new PageFactory<Map<String,Object>>().defaultPage();
        List<Map<String, Object>> articlesList= logStatedccService.selectLogArtList(page,logStatedcc);
        page.setRecords(articlesList);
        return super.packForBT(page);

    }

    /**
     * 新增猫币定期流水
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(LogStatedcc logStatedcc) {
        logStatedccService.insert(logStatedcc);
        return SUCCESS_TIP;
    }

    /**
     * 删除猫币定期流水
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer logStatedccId) {
        logStatedccService.deleteById(logStatedccId);
        return SUCCESS_TIP;
    }

    /**
     * 修改猫币定期流水
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(LogStatedcc logStatedcc) {
        logStatedccService.updateById(logStatedcc);
        return SUCCESS_TIP;
    }

    /**
     * 猫币定期流水详情
     */
    @RequestMapping(value = "/detail/{logStatedccId}")
    @ResponseBody
    public Object detail(@PathVariable("logStatedccId") Integer logStatedccId) {
        return logStatedccService.selectById(logStatedccId);
    }
}
